﻿using Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule;
using Landpy.CruiseControlNet.ConfigurationSidekick.ParserModule;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigPropertyModule
{
    class TriggerHandler : GetPropertiesHandler
    {
        public override object GetPropertiesObject(GetPropertiesContext getPropertiesContext)
        {
            var treeNodeIndentity = this.GetTreeNodeIndentity(getPropertiesContext);
            if ((treeNodeIndentity.Type & TreeNodeType.Trigger) != TreeNodeType.Unknow)
            {
                ProjectChildCollectionKey projectChildCollectionKey = ProjectChildCollectionKeyUtil.GetKey(treeNodeIndentity.Key);
                return this.TriggerRepository.GetTriggerById(getPropertiesContext.CruiseControl,
                                                             projectChildCollectionKey.ProjectId,
                                                             projectChildCollectionKey.Id);
            }
            return this.Successor.GetPropertiesObject(getPropertiesContext);
        }
    }
}
